package com.ushine.web.component.task.config;

import com.ushine.web.component.task.handler.TemplateAsyncExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;

import javax.annotation.Resource;
import java.util.concurrent.Executor;

/**
 * @Author: yls
 * @Date: 2021/04/28 22:40
 * @Description: 配置spring boot 多线程支持
 * @Version 1.0
 */
@Slf4j
@Configuration
@EnableAsync
public class AsyncDefaultTaskConfig implements AsyncConfigurer {

    @Resource
    private AsyncConfig asyncConfig;

    @Resource
    private SystemAsyncConfig systemAsyncConfig;

    /**
     * 功能描述:
     * 〈异步任务执行器〉
     *
     * @return : java.util.concurrent.Executor
     * @author : yls
     * @date : 2021/04/28 22:44
     */
    @Override
    public Executor getAsyncExecutor() {
        return asyncConfig.initExecutor(systemAsyncConfig);
    }


    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        return new TemplateAsyncExceptionHandler();
    }

}
